package com.example.arithmeticleetcode.leetcode.october;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-22 10:52
 **/
public class Demo13 {

    public static void main(String[] args) {
        int[] distance1 = {7, 10, 1, 12, 11, 14, 5, 0};
        System.out.println(distanceBetweenBusStops(distance1, 7, 2));

        System.out.println(1 << 2);//* 2^2 = 4
        System.out.println(8 >> 3);// / 2^3 = 1
        System.out.println(8 >>> 3);// / 2^3 = 1

    }


    public static int distanceBetweenBusStops(int[] distance, int start, int destination) {
        if (distance.length < 1 || start == destination) {
            return 0;
        }
        int totalDistance = 0;
        int startAndDestinationDistance = 0;
        for (int i = 0, len = distance.length; i < len; i++) {
            if ((i >= start && destination > i) || (i >= destination && i < start)) {
                startAndDestinationDistance += distance[i];
            }
            totalDistance += distance[i];
        }
        int remainDistance = totalDistance - startAndDestinationDistance;
        return remainDistance > startAndDestinationDistance ? startAndDestinationDistance : remainDistance;
    }
}
